package com.qf.controller;

import com.qf.business.entity.Student;
import com.qf.business.service.StudentService;
import com.qf.business.utils.PinyinUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * description:
 * author: Ken
 * 公众号：Java架构栈
 */
@Controller
@RequestMapping("/stu")
public class StuController {

    @Autowired
    private StudentService studentService;

    /**
     * 根据学生姓名生成拼音
     * @param name
     * @return
     */
    @RequestMapping("/genpinyin")
    @ResponseBody
    public String genPinyin(String name){

        //根据姓名生成拼音
        String pinyin = PinyinUtils.str2Pinyin(name);

        return "{\"result\":\"" + pinyin + "\"}";
    }

    /**
     * 跳转到学员的账号分配的页面
     * @return
     */
    @RequestMapping("/toregister")
    public String toRegister(){
        return "sturegister";
    }

    /**
     * 账号分配
     * @return
     */
    @RequestMapping("/register")
    public String register(Student student){
        studentService.save(student);
        return "sturegistersucc";
    }
}
